package com.dks.repository.impl;

import com.dks.mapper.DepartmentMapper;
import com.dks.models.Department;
import com.dks.repository.IDepartmentRepository;
import com.dks.result.ResultModel;
import com.dks.util.Commond;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

import static com.dks.util.Commond.MSG_SUCCESS;

@Repository
public class DepartmentRepository implements IDepartmentRepository {

    @Resource
    private DepartmentMapper departmentMapper;


    @Override
    public ResultModel<Boolean> insert(Department department) {
        ResultModel resultModel = new ResultModel();
        int row = departmentMapper.insert(department);
        if (1 == row) {
            resultModel.setCode(Commond.CODE_SUCCESS);
            resultModel.setMessage(Commond.MSG_SUCCESS);
            resultModel.setData(row);
        } else {
            resultModel.setCode(Commond.CODE_FAIL);
            resultModel.setMessage(Commond.MSG_FALE);
            resultModel.setData(row);
        }
        return resultModel;
    }

    @Override
    public ResultModel<Boolean> update(Department department) {
        ResultModel resultModel = new ResultModel();
        int row = departmentMapper.update(department);
        resultModel.setCode(Commond.CODE_SUCCESS);
        resultModel.setMessage(Commond.MSG_SUCCESS);
        return resultModel;
    }

    @Override
    public ResultModel<Boolean> delete(Department department) {
        ResultModel resultModel = new ResultModel();
        department.setRecStatus(1);
        int row = departmentMapper.update(department);
        if (1 == row) {
            resultModel.setCode(Commond.CODE_SUCCESS);
            resultModel.setMessage(Commond.MSG_SUCCESS);
            resultModel.setData(row);
        } else {
            resultModel.setCode(Commond.CODE_FAIL);
            resultModel.setMessage(Commond.MSG_FALE);
            resultModel.setData(row);
        }
        return resultModel;
    }

    @Override
    public ResultModel<Boolean> select(Integer id) {
        ResultModel resultModel = new ResultModel();
        Department Department = departmentMapper.select(id);
        resultModel.setCode(Commond.CODE_SUCCESS);
        resultModel.setMessage(MSG_SUCCESS);
        resultModel.setData(Department);
        
        return resultModel;
    }

    @Override
    public ResultModel<Boolean> getByMapList(Map<String, Object> map) {
        ResultModel resultModel = new ResultModel();
        List<Department> Departments = departmentMapper.getByMapList(map);
        resultModel.setCode(Commond.CODE_SUCCESS);
        resultModel.setMessage(MSG_SUCCESS);
        resultModel.setData(Departments);
        return resultModel;
    }


}
